//package com.example.webdownloadserver.util;
//
//import com.alibaba.fastjson.JSON;
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.ByteArrayOutputStream;
//import java.io.File;
//import java.io.IOException;
//import java.io.InputStream;
//import java.net.HttpURLConnection;
//import java.net.MalformedURLException;
//import java.net.URL;
//import java.util.Map;
//
///**
// *
// * <p>
// * http 发送post请求
// * </p>
// *
// * @title HttpUtil.java
// * @package com.dnkj.pay.service.impl.channel.util
// * @author ying.xiao
// * @version 0.1 2020年11月23日
// */
//@Slf4j
//public class HttpUtil {
//
//	@SuppressWarnings("unchecked")
//	public static Map<String, String> sendString(String context, String url) throws IOException {
//		CloseableHttpResponse response = null;
//		CloseableHttpClient client = null;
//		Map<String, String> resultMap = null;
//		try {
//			HttpPost httpPost = new HttpPost(url);
//			StringEntity entityParams = new StringEntity(context, "utf-8");
//			httpPost.setEntity(entityParams);
//			httpPost.setHeader("Content-Type", "application/json");
//			RequestConfig config = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(2000)
//					.setSocketTimeout(5000).build();
//			httpPost.setConfig(config);
//			client = HttpClients.createDefault();
//			response = client.execute(httpPost);
//			log.info("HttpUtil send requst:{} response:{}", context, response);
//			if (response != null && response.getEntity() != null) {
//				String result = new String(EntityUtils.toByteArray(response.getEntity()), "utf-8");
//				log.info("HttpUtil send result:{}", result);
//				resultMap = JSON.parseObject(result, Map.class);
//				log.info("HttpUtil send resultMap:{}", JSON.toJSONString(resultMap));
//			}
//		} catch (Exception e) {
//			log.error("HttpUtil sendString error:{}",e);
//			throw e;
//		} finally {
//			if (response != null) {
//				response.close();
//			}
//			if (client != null) {
//				client.close();
//			}
//		}
//		return resultMap;
//	}
//
//	public static byte[] downloadBill(String urlStr) throws IOException {
//		HttpURLConnection httpUrlConnection = null;
//		InputStream fis = null;
//		try {
//			URL url = new URL(urlStr);
//			httpUrlConnection = (HttpURLConnection) url.openConnection();
//			httpUrlConnection.setConnectTimeout(5 * 1000);
//			httpUrlConnection.setDoInput(true);
//			httpUrlConnection.setDoOutput(true);
//			httpUrlConnection.setUseCaches(false);
//			httpUrlConnection.setRequestMethod("GET");
//			httpUrlConnection.setRequestProperty("CHARSET", "UTF-8");
//			httpUrlConnection.connect();
//			fis = httpUrlConnection.getInputStream();
//
//			byte[] bytes = streamToByte(fis);
//			log.info("获取文件数组大小"+bytes.length);
//			return bytes;
//		} catch (MalformedURLException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} catch (Exception e){
//			e.printStackTrace();
//			throw e;
//		}finally {
//			if (fis != null)
//				fis.close();
//			if (httpUrlConnection != null)
//				httpUrlConnection.disconnect();
//		}
//		return null;
//	}
//
//	private static byte[] streamToByte(InputStream inputStream) throws IOException {
//		ByteArrayOutputStream baos = new ByteArrayOutputStream();
//		byte buff[] = new byte[1024];
//		int len = 0;
//		while ((len = inputStream.read(buff)) != -1) {
//			baos.write(buff, 0, len);
//		}
//		baos.flush();
//		return baos.toByteArray();
//	}
//
//
//}
